<script>
  import {
    mapState,
    mapMutations
  } from 'vuex'
  export default {
    onLaunch: function() {
      console.log('App Launch');
      // 从本地获取 Token
      const token = uni.getStorageSync('token');
      if (token) {
        // 如果有 Token，发送到后端验证
        this.checkToken();
      }
      console.log('App Launch');
    },
    onShow: function() {
      console.log('App Show');
    },
    onHide: function() {
      console.log('App Hide');
    },
    methods: {
      ...mapMutations('my_user', ['updateUserInfo', 'updateToken', 'updateAddress']),
      //请求所有参加活动的人
      async checkToken() {
        const {
          data: res
        } = await uni.$http.get('/token');
        console.log(res);
        if (res.code !== 1 && res.msg === 'NOT_LOGIN') {
          this.updateUserInfo({});
          this.updateToken('');
          this.updateAddress({});
        }
      }
    },
  };
</script>

<style>
  /* 解决头条小程序组件内引入字体不生效的问题 */
  /* #ifdef MP-TOUTIAO */
  @font-face {
    font-family: uniicons;
    src: url('/static/uni.ttf');
  }

  /* #endif */
</style>
